package com.gongpingjialoan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.DealerCat;

import java.util.List;

/**
 * Created by Administrator on 2016/5/13.
 */
public class SortAdapter extends BaseAdapter {

    Context mContext;
    LayoutInflater mLayoutInflater;
    List<DealerCat> list;

    int currentposition = -1;


    public SortAdapter(Context context) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<DealerCat> list) {
        this.list = list;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if (list == null) {
            return 0;
        }
        return list.size();
    }

    public void setCurrentPosition(int position) {
        currentposition = position;
        notifyDataSetChanged();
    }

    @Override
    public DealerCat getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.item_sort, null);
        }

        TextView nameT = (TextView) convertView.findViewById(R.id.name);

        nameT.setText(list.get(position).getName());

        if (currentposition == position) {
            nameT.setTextColor(mContext.getResources().getColor(R.color.text_blue));
        } else {
            nameT.setTextColor(mContext.getResources().getColor(R.color.text_black));
        }


        return convertView;
    }
}
